#{extends 'common/supervisor.html' /} 
#{set title:'添加产品' /} 

%{
	boolean isSecondBid = constants.Constants.IS_SECOND_BID;
}%

<script type="text/javascript" src="@{'/public/javascripts/uuid.js'}"></script>
<!-- 内容区域 -->
<div class="xn_c_contentwarp">
  <div class="xn_c_contentlist">
  <!--左-->
  #{include "supervisor/webContentManager/common/leftBar.control"/}
  <!--右-->
  #{form @addingProduct(product), method:'POST', id:'addingProduct' }
  <div class="xn_c_content">
    <div class="xf_content_add">
      <div class="xfht_t_j_y_2">
        <!--右上-->
        <div class="xf_ht_obu_fklm">添加借款标产品
          <div class="xf_htgl_jgtitle_r">
            <a onclick="showLabel();" id="xf_dfk_offbtt_tcc2" style="margin-top: 20px; cursor: pointer;">添加产品标签</a>
          </div>
        </div>
        <!-- 借款产品简介 -->
        <div class="xf_htgl_jgone">
          <div class="xf_htgl_pro_title clr">
            <h3 class="xf_htgl_jgtitle xf_htgl_jgtitle_l">借款产品简介</h3>
            <div class="xf_htgl_jgtitle_r">
              <a onclick="showFrame(0);" id="xf_dfk_offbtt_tcc" style="cursor: pointer;">添加字段</a> 
            </div>
          </div>
          <div class="xf_ht_gl_jgone_map" id="fieldIntro">
            #{table border:"0", cellspacing:"0", cellpadding:"0", width:"100%", class:"xf_ht_pro_tjhe_table"}
              #{tr}
                #{td width:"140", align:"right", valign:"middle"}借款标名称：#{/td}
                #{td}<input class="xfht_zr_input xfht_zr_input_shoping" type="text" name="product.name" id="name" onblur="checkName(this);" value="${goods?.name}">#{/td}
              #{/tr}
              #{tr}
                 #{td width:"140", align:"right", valign:"middle"}适合人群：#{/td}
                 #{td}<input class="xfht_zr_input xfht_zr_input_shoping" type="text" name="product.fitCrowd" id="fitCrowd">#{/td}
              #{/tr}
              #{tr}
                 #{td width:"140", align:"right", valign:"top"}产品亮点：#{/td}
                 #{td}<textarea class="xf_ht_baidu_wkttcc_text" name="product.characteristic" id="characteristic" ></textarea>#{/td}
              #{/tr}
            #{/table}
          </div>
        </div>
        <!-- 借款产品详细描述 -->
        <div class="xf_htgl_jgone">
          <div class="xf_htgl_pro_title clr">
            <h3 class="xf_htgl_jgtitle xf_htgl_jgtitle_l">借款产品详细描述</h3>
            <div class="xf_htgl_jgtitle_r">
              <a onclick="showFrame(1);" id="xf_dfk_offbtt_tcc" style="cursor: pointer;">添加字段</a>
            </div>
          </div>
        <div class="xf_ht_gl_jgone_map" id="fieldDescribe">
          #{table border:"0", cellspacing:"0", cellpadding:"0", width:"100%", class:"xf_ht_pro_tjhe_table"}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">额度范围：</span>
                  <input class="xfht_zr_input" type="text" style="width:80px;" name="product.minAmount" id="minAmount" onkeyup="value=value.replace(/[^\d]/g,'')">
                  - 
                  <input class="xfht_zr_input" type="text" style="width:80px;" name="product.maxAmount" id="maxAmount" onkeyup="value=value.replace(/[^\d]/g,'')">
                <span style="padding-left:30px;">贷款利率：</span>
                  <input class="xfht_zr_input" type="text" style="width:80px;" name="product.minInterestRate" id="minInterestRate" onkeyup="value=value.replace(/[^\d\.]/g, '').replace(/(\.\d{2}).*/g, '$1')">%
                  - 
                  <input class="xfht_zr_input" type="text" style="width:80px;" name="product.maxInterestRate" id="maxInterestRate" onkeyup="value=value.replace(/[^\d\.]/g, '').replace(/(\.\d{2}).*/g, '$1')">%
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">贷款期限：</span>(期限不可超过5年，出现重复数据，系统会尝试截取!)
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">年：</span>
                <span id="yy"><input type="hidden" id="periodYear" name="product.periodYear"/></span>
                <input class="xfht_zr_input xfht_zr_input_pro1" type="text" style="width:24px;" value="+"  onclick="addTextBox('yy')" id="addYear" readonly="readonly"/> 
				<input class="xfht_zr_input xfht_zr_input_pro1" type="text" value="-" readonly="readonly" style="width:24px;margin-left: 5px;display: none;" id="delyy" onclick="delTextBox('yy')"/>
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">月：</span>
                <span id="mm"><input type="hidden" id="periodMonth" name="product.periodMonth"/></span>
                <input class="xfht_zr_input xfht_zr_input_pro1" type="text" style="width:24px;" value="+"  onclick="addTextBox('mm')" readonly="readonly"/> 
				<input class="xfht_zr_input xfht_zr_input_pro1" type="text" value="-" readonly="readonly" style="width:24px;margin-left: 5px;display: none;" id="delmm" onclick="delTextBox('mm')"/>
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">日：</span>
                <span id="dd"><input type="hidden" id="periodDay" name="product.periodDay"/></span>
                <input class="xfht_zr_input xfht_zr_input_pro1" type="text" style="width:24px;" value="+"  onclick="addTextBox('dd')" readonly="readonly"/> 
				<input class="xfht_zr_input xfht_zr_input_pro1" type="text" value="-" readonly="readonly" style="width:24px;margin-left: 5px;display: none;" id="deldd" onclick="delTextBox('dd')"/>
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">投标时间(日):</span>
                <span id="ip"><input type="hidden" id="investPeriod" name="product.investPeriod"/></span>
                <input class="xfht_zr_input xfht_zr_input_pro1" type="text" style="width:24px;" value="+"  onclick="addTextBox('ip')" readonly="readonly" />
				<input class="xfht_zr_input xfht_zr_input_pro1" type="text" value="-" readonly="readonly" style="width:24px;margin-left: 5px; display: none;" id="deli" onclick="delTextBox('ip')"/>
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">审核时间：</span> <input class="xfht_zr_input" type="text" style="width:80px;" name="product.auditCycle" id="auditCycle" onkeyup="value=value.replace(/[^\d]/g,'')">
                <span class="xf_span_tdfx2">工作日</span>
                <span style="padding-left:30px;">还款方式：</span>
                #{list rtypes}
				  #{if _?.isUse }
				    <input type="checkbox" name="product.repaymentTypeId" value="${_?.id}" checked="checked"/>${_?.name }
				  #{/if}
				  #{else}
				    <input type="checkbox"  disabled="disabled"/>
				    <span style="color: red;">${_?.name }</span>
				  #{/else}
				#{/list}
              #{/td}
            #{/tr}
            #{tr}
              #{td align:"left", valign:"middle"}
                <span class="xf_span_tdfx">最低投标金额：</span> <input class="xfht_zr_input" type="text" style="width:80px;" name="product.minInvestAmount" id="minInvestAmount" onkeyup="value=value.replace(/[^\d]/g,'')">
                <span class="xf_span_tdfx2">元</span>
                <span style="padding-left:30px;">借款标最高拆分份数：</span>
                <input class="xfht_zr_input" type="text" name="product.maxCopies" id="maxCopies" style="width:80px;" onkeyup="value=value.replace(/[^\d]/g,'')"> 份
              #{/td}
            #{/tr}
            #{tr}
              #{td}
                <span class="xf_ht_sxf_pro"><span class="xf_span_tdfx">手续费：</span></span><textarea readonly="readonly"  class="xf_ht_baidu_wkttcc_text">借款期限${borrowFeeMonth}个月（含）以下，借款成功后，收取本金的${strfee}%；借款期限${borrowFeeMonth}个月以上，借款成功后，收取本金的${strfee}%以外，还另外收取超过月份乘本金的${borrowFeeRate}%（不成功不收取成交服务费）</textarea>
              #{/td}
            #{/tr}
          #{/table}
        </div>
      </div>

      <!-- 申请人条件 -->
      <div class="xf_htgl_jgone" id="labelContent2">
        <div class="xf_htgl_pro_title clr">
          <h3 class="xf_htgl_jgtitle xf_htgl_jgtitle_l">申请人条件</h3>
          <div class="xf_htgl_jgtitle_r">
             <a onclick="showFrame(2);" id="xf_dfk_offbtt_tcc" style="cursor: pointer;">添加字段</a>
          </div>
        </div>
        <div class="xf_ht_gl_jgone_map" id="fieldCondition">
          #{table border:"0", cellspacing:"0", cellpadding:"0", width:"100%", class:"xf_ht_pro_tjhe_table"}
            #{tr}
              #{td width:"140", align:"right", valign:"top"}申请人条件：#{/td}
              #{td}<textarea class="xf_ht_baidu_wkttcc_text" name="product.applicantCondition" id="applicantCondition"></textarea>#{/td}
            #{/tr}
          #{/table}
        </div>
      </div>
      <!-- 必须审核资料（完成审核，即可成功借款） -->
      <div class="xf_htgl_jgone">
        <div class="xf_htgl_pro_title clr">
          <h3 class="xf_htgl_jgtitle xf_htgl_jgtitle_l">必须审核资料<span class="xfht_red">（完成审核，即可成功借款）</span></h3>
        </div>
        <div class="xf_ht_gl_jgone_map">
          #{table border:"0", cellspacing:"0", cellpadding:"0", width:"100%", class:"xf_ht_pro_tjhe_table"}
            #{tr}
              #{td width:"210", align:"left", valign:"top", colspan:"2"}
                <!-- 必选资料选项过后显示层  -->
			    <div id="showRItem" ></div>
              #{/td}
            #{/tr}
            #{tr}
              #{td width:"140"}&nbsp;#{/td}
              #{td}<input class="xf_ggnr_help_input" type="button" value="添加审核科目" onclick="showRItem();">#{/td}
            #{/tr}
          #{/table}
        </div>
      </div>
      <div class="xf_htgl_jgone">
        <div class="xf_htgl_pro_title clr">
          <h3 class="xf_htgl_jgtitle xf_htgl_jgtitle_l">可选审核资料（用于加快满标速度，同时可超额借款）</h3>
        </div>
        <div class="xf_ht_gl_jgone_map">
          #{table border:"0", cellspacing:"0", cellpadding:"0", width:"100%", class:"xf_ht_pro_tjhe_table"}
            #{tr}
              #{td width:"210", align:"left", valign:"top", colspan:"2"}
                <!-- 可选资料选项过后显示层  -->
			    <div id="showSItem" ></div>
              #{/td}
            #{/tr}
            #{tr}
              #{td width:"140"}&nbsp;#{/td}
              #{td}
                <input class="xf_ggnr_help_input" type="button" value="添加审核科目" onclick="showSItem();">
                <span class="xfht_red">&nbsp;&nbsp;&nbsp;&nbsp;<br/>财富提示：每多提交一份可选审核资料，可提高借款额度2000—5000元。</span>
              #{/td}
            #{/tr}
          #{/table}
        </div>
      </div>
      <!-- 最低信用要求 -->
      <div class="xf_htgl_jgone">
        <div class="xf_ht_zdxy_yl">
          #{table border:"0", cellspacing:"0", cellpadding:"0", width:"100%", class:"xf_ht_pro_tjhe_table"}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l"}最低信用要求：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <select name="product.creditId" class="xfht_t_j_td_1" style="width: 120px;">
				  #{list creditLevels}
				    <option value="${_?.id}">${_?.name}</option>
					#{/list}
				</select>
              #{/td}
            #{/tr}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l"}借款模式：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <input type="radio" name="product.loanType" value="0" id="loanType0" checked="checked"><span id="sloanType0" style="padding-right:10px;">普通</span>
                <input type="radio" name="product.loanType" value="1" id="loanType1"> <span id="sloanType1" style="padding-right:10px;">信用</span>
                <input type="radio" name="product.loanType" value="2" id="loanType2"> <span id="sloanType2" style="padding-right:10px;">净值</span>
                #{if isSecondBid}
                <input type="radio" name="product.loanType" value="3" id="loanType3"> <span id="sloanType3" style="padding-right:10px;">秒还</span>
                (净值、秒还产品允许一种)
                #{/if}
              #{/td}
            #{/tr}
            #{if !constants.Constants.IPS_ENABLE}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l", align:"right", valign:"top"}购买模式：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <input type="radio" name="product.isDealPassword" value="1" checked="checked" > 需要交易密码（有关资金流动，建议勾选交易密码）<br />
                <input type="radio" name="product.isDealPassword" value="0"> 不需要交易密码（选择此项后，可将平台上同类借款标的借款图片统一起来）
              #{/td}
            #{/tr}
            #{/if}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l", align:"right", valign:"top"}借款图片：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <input type="radio" name="product.loanImageType" value="0" onclick="hidePlatformImag();" checked="checked"> 用户上传（选择此项后，用户可在发布借款页面自己上传与借款标内容相符的图片）<br />
                <input type="radio" name="product.loanImageType" value="1" onclick="showPlatformImag();" id="rloanImageFilename"> 平台上传（选择此项后，可将平台上同类借款标的借款图片统一起来）<br />
                <div class="xf_ht_pro_jkbimg_hezi" id="imgArea" style="display:none;">
                  <img class="xf_ht_pro_jkbimg" alt=""  id="loanImage">
                  <input type="hidden" name="product.loanImageFilename" id="loanImageFilename" />
                  <span style="position: relative;/*top: 25px;*/">
		            <input type='button' class='upload_btn' value='上传' style="display:inline-block; margin:30px 0;float:left;"/> 
		            <input type="file" class="upload_file" name="imgFile" id="imgFile" onchange="uploadImage('imgFile','loanImage');" style="top: 30px;*top:50px !important;left: -70px;"/>
		          </span>
                </div>
                <span class="xf_ggnr_help_input_text">友情提示：图片大小110*110px</span>
              #{/td}
            #{/tr}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l"}借款小图标：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <div class="xf_ht_pro_jkbimg_hezi xf_ht_pro_jkbimg_hezix">
                  #{img src:"", class:"xf_ht_pro_jkbimg",id:"smallImag"}#{/img}
                  <input type="hidden" name="product.smallImageFilename" id="smallImageFilename" />
				  <span style="position: relative;/*top: 25px;*/">
		            <input type='button' class='upload_btn' value='上传' style="display:inline-block; margin:30px 0;float:left;"/> 
		            <input type="file" class="upload_file" name="imgFile" id="smallfile" onchange="uploadImage('smallfile','smallImag');" style="top: 30px;*top:40px !important;left: -70px;" />
		          </span>
                </div>
                <div style="clear:both;"></div>
                <span class="xf_ggnr_help_input_text">友情提示：图片大小25*25px</span>
              #{/td}
            #{/tr}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l"}借款产品图片：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <div class="xf_ht_pro_jkbimg_hezi">
                  #{img src:"", class:"xf_ht_pro_jkbimg xf_ht_pro_jkbimg2",id:"nameImage"}#{/img}
                  <input type="hidden" name="product.nameImageFilename" id="nameImageFilename" />
				  <span style="position: relative;top: 20px; width:100px; height:26px; display:block; float:left;">
		            <input type='button' class='upload_btn' value='上传'/> 
		            <input type="file" class="upload_file" name="imgFile" id="namefile" onchange="uploadImage('namefile','nameImage');" style="top:0;left:10px;" />
		          </span>
                </div>
                <span class="xf_ggnr_help_input_text">友情提示：图片大小300*60px</span>
              #{/td}
            #{/tr}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l"}发布方式：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <input type="radio" value="1" name="product.showType" checked="checked" />PC
				<input type="radio" value="2" name="product.showType" />APP
				<input type="radio" value="3" name="product.showType" />PC+APP
              #{/td}
            #{/tr}
            #{tr}
              #{td class:"xf_ht_zdxy_yl_l"}借款保证金：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                                             冻结借款本金
                 <input class="xfht_zr_input" type="text" name="product.bailScale" id="bailScale" style="width:80px;" onkeyup="value=value.replace(/[^\d\.]/g, '').replace(/(\.\d{2}).*/g, '$1')"> % 
                                             作为借款保证金
              #{/td}
            #{/tr}
            #{tr class:"xf_tr_last_boder"}
              #{td class:"xf_ht_zdxy_yl_l"}产品排序：#{/td}
              #{td class:"xf_ht_zdxy_yl_r"}
                <input class="xfht_zr_input" type="text" name="product.order" id="order" style="width:80px;" onkeyup="value=value.replace(/[^\d]/g,'')">
              #{/td}
            #{/tr}
          #{/table}
        </div>
      </div>
    </div>
    <div class="xf_ht_news_content_button">
      <input type="hidden" id="lables" name="product.jsonLables"/>
      <input class="xf_ht_tcc_button_ok" type="submit" value="保 存">
      <input class="xf_ht_tcc_button_on" type="button" value="取 消" onclick='location.href= "@{productList()}"'>
    </div>
    </div>
    </div>
    #{include '/supervisor/webContentManager/ProductAction/requiredAuditItem.control'/}
    #{include '/supervisor/webContentManager/ProductAction/selectAuditItem.control'/}
    #{/form}
    #{include '/supervisor/webContentManager/ProductAction/addLable.control'/}
    #{include '/supervisor/webContentManager/ProductAction/addField.control'/}
  </div>
</div>
<script type="text/javascript">
  var i1 = 0; // 控制年期限
  var i2 = 0; // 控制月期限
  var i3 = 0; // 控制日期限
  var j = 0;  // 控制投标期限

  /* 添加框框触发 */
  function addTextBox(id) {
    var input = null;
    switch (id) {
      case "yy":
        $("#delyy").show(); i1++; var value = id + i1;
        input = "<input type='text' id='"+ value + "' maxlength='1' style='width: 20px; margin-left: 5px;' class='xfht_zr_input' onkeyup=\"keyup(this);\" />";
        if(i1 >=5 ) $("#addYear").hide();
        break;
      case "mm":
        $("#delmm").show(); i2++; var value = id + i2;
        input = "<input type='text' id='"+ value + "' maxlength='2' style='width: 20px; margin-left: 5px;' class='xfht_zr_input' onkeyup=\"keyup(this);\" />";
        break;
      case "dd":
        $("#deldd").show(); i3++; var value = id + i3;
        input = "<input type='text' id='"+ value + "' maxlength='3' style='width: 20px; margin-left: 5px;' class='xfht_zr_input' onkeyup=\"keyup(this);\" />";
        break;
      case "ip":
        $("#deli").show(); j++; var value = id + j;
        input = "<input type='text' name='"+ value + "' id='" + value + "' maxlength='2' style='width: 20px; margin-left: 5px;' class='xfht_zr_input' onkeyup=\"keyup(this);\" />";
        break;
      }
      $("#" + id).append(input);
  }
	
  /* 减去框框触发 */
  function delTextBox(id) {
    switch (id) {
      case "yy": $("#" + (id + i1)).remove(); i1--; if (i1 < 1) { i1 = 0; $("#delyy").hide(); } if(i1 < 5){ $("#addYear").show();} break;
      case "mm": $("#" + (id + i2)).remove(); i2--; if (i2 < 1) { i2 = 0; $("#delmm").hide(); } break;
      case "dd": $("#" + (id + i3)).remove(); i3--; if (i3 < 1) { i3 = 0; $("#deldd").hide(); } break;
      case "ip": $("#" + (id + j)).remove(); j--; if (j < 1) { j = 0; $("#deli").hide(); } break;
    }
  }

  /* 去重复且排序 */
  Array.prototype.unique = function () { 
    return this.sort(function compare(a, b){
      return a - b;
      }).join(",,")
      .replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4")
      .replace(/,,+/g,",")
      .replace(/,$/,"")
      .split(",");
  }
		
  /* 给动态框框中填充值 */
  function setValue(){
    /* 填充年期限单位 */
    var po = null;
    var value = new Array();
    var val = "";
    for(var p = 1; p <= i1; p++){
      po = $("#yy"+p);
      val = po.val();
      if(val != null && val != ""){
        if(val > 5 || val <= 0){
          alert("年期限：”"+ val + "“需在[1~5]年(包含5)之间!");
          
          return false;
        }
        value[p-1] = val;
      }
    }
    if(value.length <= 0) {
      alert("请填写年期限!");
      return false;
    }
    $("#periodYear").val(value.unique()); 

    /* 填充月期限单位 */
    po = null;
    value = new Array();
    for(var p = 1; p <= i2; p++){
      po = $("#mm"+p);
      val = po.val();
      if(val != null && val != ""){
        if(val > (5 * 12) || val <= 0){
          alert("月期限：”"+ val + "“需在[1~60]月(包含60)之间!");
          
          return false;
        }
        value[p-1] = val;
      }
    }
    if(value.length <= 0) {
      alert("请填写月期限!");
      
      return false;
    }
    $("#periodMonth").val(value.unique());
		
    /* 填充日期限单位 */
    po = null;
    value = new Array();
    for(var p = 1; p <= i3; p++){
      po = $("#dd"+p);
      val = po.val();
      if(val != null && val != ""){
        if(val > 10000 || val <= 0){
          alert("日期限：”"+ val + "“需在[1~10000]日(包含10000)之间!");
          
          return false;
        }
        value[p-1] = val;
      }
    }
    if(value.length <= 0) {
      alert("请填写日期限!");
      
      return false;
    }
    $("#periodDay").val(value.unique()); 
		
    /* 填充投标期限 */
    po = null;
    value = new Array();
    for(var p = 1; p <= j; p++){
      po = $("#ip"+p);
      val = po.val();
      if(val != null && val != ""){
        value[p-1] = val;
      }
    }
    if(value.length <= 0) {
      alert("请填写投标期限!");
      
      return false;
    }
    $("#investPeriod").val(value.unique());

    return true;
  }
	
  /* 借款期限和投标期限具有焦点并释放某个键盘键 */
  function keyup(po){
    /* 限制是数字,直接内嵌 有点小问题,待改善 */
    po.value= po.value.replace(/[^\d]/g,'');
  }
	
  /* 显示平台上传图片层 */
  function showPlatformImag(){
    $("#imgArea").show();
  }
	
  /* 隐藏平台上传图片层 */
  function hidePlatformImag(){
    $("#imgArea").hide();
  }
	
  /* 显示必选资料层 */
  function showRItem(){
    $.layer({
        type: 1,
        area: ['800', '450'],
        title: '添加必选资料',
        page: {dom : '#raudtitems'}
      });
  }
	
  /* 显示可选资料层 */
  function showSItem(){ 
    $.layer({
        type: 1,
        area: ['800', '450'],
        title: '添加可选资料',
        page: {dom : '#saudtitems'}
      });
  }
	  
  /* 显示已经勾选了的必选资料名称  */
  function showRName(lenth) {
    var value = "";
    var chk = null;
    var j = 0;
    for(var i = 1; i <= lenth; i++){
      /* 不支持JQuery用 document.getElementById获取 */
      chk = document.getElementById("rid" + i);
      if(chk.checked){
        j++;
        value += j + "、" + '<span style="margin-left: 20px;margin-top: 20px;" >' + $("#rname" + i).val() + '</span><br/>';

        $("#sid" + i).attr("disabled","disabled");
      }else{
    	if($("#sid" + i).attr("disabled") == "disabled")
    	   $("#sid" + i).removeAttr("disabled");
      }
    }

    /* 勾选后显示层,填充数据 */
    $("#showRItem").html(value).show();
    layer.closeAll();
  }
	
  /* 显示已经勾选了的可选资料名称  */
  function showSName(lenth) {
    var value = "";
    var chk = null;
    var j = 0;
    for(var i = 1; i <= lenth; i++){
      chk = document.getElementById("sid" + i);
      if(chk.checked){
        j++;
        value += j + "、" + '<span style="margin-left: 20px;margin-top: 20px;" >' + $("#sname" + i).val() + '</span><br/>';

        $("#rid" + i).attr("disabled","disabled");
      }else{
    	  if($("#rid" + i).attr("disabled") == "disabled")
    	   $("#rid" + i).removeAttr("disabled");
      }
    }
    /* 勾选后显示层,填充数据 */
    $("#showSItem").html(value).show();
    /* 可选资料层隐藏 */
    $('#saudtitems').hide();
    layer.closeAll();
  }
	
  /* 检查名称是否唯一 */
  function checkName(po){
    var action = #{jsAction @checkName(':name',':id',':flag') /};
    $.post(action({name:encodeURI(po.value),id:0,flag:1}), function(data) {
      if(data) {
        $(po).css("color","red").val("产品名称重复!");
      }else {
        $(po).css("color","green");
      }
    });
  } 
	
  $(function(){
	/* 高亮显示 */
	showHighLight(4, 4, 13);
		
    /* 借款模式限制 */
    for(var i = 2; i < 4; i++){
      #{list loanTypes}
      /* 不屏蔽普通和信用*/
      if(${_} == i){
        $("#loanType" + i).attr("disabled", "disabled");
        $("#sloanType" + i).css("color", "red");
      }
      #{/list}
    } 
		
    /* 给表单注册 onsubmit 事件 */
    $("#addingProduct").submit(function (){
      var name = $("#name").val();
      if(name == "" || name == "产品名称重复!"){
        alert("请填写产品名称!");
        
        return false;
      }
			
      if($("#fitCrowd").val() == ""){
        alert("请填写适合人群!");
        
        return false;
      }
			
      if($("#characteristic").val() == ""){
        alert("请填写产品亮点!");
        
        return false;
      }
			 
      var minAmount = $("#minAmount").val();
      var maxAmount = $("#maxAmount").val();
      if(minAmount == "" || maxAmount == "" ){
        alert("请填写额度范围!");
        
        return false;
      }
      minAmount = minAmount * 1;
      maxAmount = maxAmount * 1;
      if(maxAmount > 50000000){
    	  alert("额度上限不能超过[50000000]!");
          
          return false;
      }
      if(minAmount > 50000000 || minAmount > maxAmount || minAmount < 0){
        alert("额度下限有误!");
        
        return false;
      }

      var minInterestRate = $("#minInterestRate").val();
      var maxInterestRate = $("#maxInterestRate").val();

      if(minInterestRate == "" || maxInterestRate == "" ){
        alert("请填写贷款利率!");
        
        return false;
      }
      minInterestRate = minInterestRate * 1;
      maxInterestRate = maxInterestRate * 1;
      if(minInterestRate > maxInterestRate ){
          alert("贷款利率下限不能大于贷款利率上限 !");
          
          return false;
    	  
      }
      if( minInterestRate < ${constants.Constants.MIN_INTEREST_RATE} ){
        alert("贷款利率下限不能小于 1% !");
        
        return false;
      }
			
      if( maxInterestRate > ${constants.Constants.MAX_INTEREST_RATE}){
        alert("贷款利率上限不能大于24% !");
        
        return false;
      }

      /* 得到动态生成框中的值   年、月、日、投标期限  */
      if(!setValue()) return false;
			
        if($("#auditCycle").val() == ""){
          alert("请填写审计时间!");
          
          return false;
        }

        /* 还款方式 */
        var repaymentTypeId = $("input[type=checkbox][name='product.repaymentTypeId']:checked");
        if(repaymentTypeId.length <= 0){
          alert("请选择至少一种还款方式!");
          return false;
        }
			
        if($("#minInvestAmount").val() == ""){
          alert("请填写最低投标金额!");
          return false;
        }
			
        if($("#maxCopies").val() == ""){
          alert("请填写借款标最高拆分份数!");
          
          return false;
        }

        if($("#applicantCondition").val() == ""){
            alert("请填写申请人条件!");
            
            return false;
        }

        /* 选中的必选资料 */
        var requiredAuditId = $("input[type=checkbox][name='product.requiredAuditId']:checked");
        if(requiredAuditId.length <= 0){
          alert("请选择至少一个必选资料!");
          
          return false;
        }
			
        /* 如果是选择了平台自己上传 */
        if($("#rloanImageFilename").is(":checked")){
          var loanImage = $("#loanImage").attr("src"); 
          if(typeof(loanImage) == "undefined" || loanImage == "" || loanImage.indexOf("/public/images/default.png") != -1){
            alert("请上传借款图片!");
            
            return false;
          }
          $("#loanImageFilename").val(loanImage);
        }
			 
        var smallImag = $("#smallImag").attr("src"); 
        if(typeof(smallImag) == "undefined" || smallImag == "" || smallImag.indexOf("/public/images/default.png") != -1){
          alert("请上传借款小图标!");
            
          return false;
        }
        $("#smallImageFilename").val(smallImag);

        var nameImage = $("#nameImage").attr("src"); 
        if(typeof(nameImage) == "undefined" || nameImage == "" || nameImage.indexOf("/public/images/default.png") != -1){
          alert("请上传借款产品图片!");
          
          return false;
        }
        $("#nameImageFilename").val(nameImage);
			
        if($("#bailScale").val() == ""){
            alert("请填写借款保证金!");
            
            return false;
        }
			
        if($("#order").val() == ""){
          alert("请填写产品排序!");
          
          return false;
        }
			
        for(var i = 3; i < lable.length; i++){
            var lablefield = lable[i].fields;
            if(typeof(lablefield) == 'undefined' || lablefield == null || lablefield.length == 0){
              alert('请给“'+lable[i].name+'”标签添加字段信息!');
              
              return false;
            }
          }
        	
        $("#lables").val($.toJSON(lable)); // 标签赋值

        return true;
    });
  });

  /* --------------------------------------添加标签/字段---------------------------------------- */
	
  var labno = 2; // 控制标签ID
  var filno = 0; // 控制字段ID
  var index = 2; // 控制标签索引
  var showindex = 2; // 控制显示层索引
  	
  var lable = new Array(); // 标签集合
  lable.push({},{},{}); // 初始化三个必须存在的
  lable[0].id = 0;
  lable[1].id = 1;
  lable[2].id = 2;
  lable[0].name = "借款产品简介";
  lable[1].name = "借款产品详情描述";
  lable[2].name = "申请人条件";
  lable[0].fields = [];
  lable[1].fields = [];
  lable[2].fields = [];
	
  /* 添加标签 */
  function createLabel(){
    var labelName = $.trim($("#labelName").val()); // 标签名称

    if(labelName == ""){
      alert("请填写标签名!");
        
      return;
    }
	 		  
    labno++;
    index++;
    showindex++;
    /* 标签数组赋值 */
    lable.push({});
    lable[index].id = labno;
    lable[index].name = labelName;
    lable[index].fields = [];
    
    var html = '<div class="xf_htgl_jgone" id="labelContent'+showindex+'">'+
		 		 '<div class="xf_htgl_pro_title clr">'+
	   			   '<h3 class="xf_htgl_jgtitle xf_htgl_jgtitle_l">'+labelName+'</h3>'+
	   			   '<div class="xf_htgl_jgtitle_r">'+
		     		 '<a onclick="showFrame('+labno+');" id="xf_dfk_offbtt_tcc" style="cursor: pointer;">添加字段</a>'+
		     		 '<a onclick="getLabel(this,'+labno+');" id="xf_dfk_offbtt_tcc" style="cursor: pointer;">删除</a>'+
      			   '</div>'+
				'</div>'+
				'<div class="xf_ht_gl_jgone_map" id="field'+labno+'">'+
				'</div>'+
	 		  '</div>';

	/* 在指定的ID后面添加元素 */		
	$("#labelContent"+(showindex-1)).after(html);

	closeLabel();
  }
	
  /* 添加字段 */
  function createField(){
    var fieldName = $.trim($("#fieldName").val()); // 字段名称
    var fieldContent = $.trim($("#fieldContent").val()); // 内容
		
    if(fieldName == "" || fieldContent == ""){
      alert("请填写字段名称和内容!");
      
      return;
    }

    var flag = $("#flag").val() * 1; // 得到追加的flag值
    var textType = $("#textType").val() * 1; // 字段添加类型

    filno++;

    var html = '<table width="100%" class="xf_ht_pro_tjhe_table"><tr><td width="140" align="right" valign="top">'+fieldName+'：</td><td>';
    
	if(1 == textType)
		html += '<input disabled="disabled" class="xfht_zr_input xfht_zr_input_shoping" type="text" value="'+fieldContent+'"/>';
	else
		html += '<textarea disabled="disabled" class="xf_ht_baidu_wkttcc_text">'+fieldContent+'</textarea>';

		html +=	'<a style="cursor: pointer;" onclick="getFrame(this,'+flag+','+filno+')">&nbsp;&nbsp;删除</a></td></tr></table>';

	/* 字段数组赋值 */
    var field = {};
    field.id = filno;
    field.name = fieldName;
    field.type = textType;
    field.content = fieldContent;
   
    switch(flag){
      case 0: 
        lable[0].fields.push(field);
        $("#fieldIntro").append(html); 
        break;
      case 1: 
    	lable[1].fields.push(field);
        $("#fieldDescribe").append(html); 
        break;
      case 2: 
        lable[2].fields.push(field);
        $("#fieldCondition").append(html); 
        break;
      default : 
        for(var i = 0; i < lable.length; i++){
			if(flag == lable[i].id){
				lable[i].fields.push(field);
				
				break;
			}
        }  
        $("#field" + flag).append(html); 
        
        break;
      }
    
    closeFrame();
  }
	
  /* 删除标签 */
  function getLabel(key, no){
    lable.removeObjectById(no); 
    index--;
    // 控制层显示
	if(no == showindex) {
		showindex--;
		labno--;
	}
    $(key).parent().parent().parent().remove(); 
  }
	
  /* 删除字段 */
  function getFrame(key, flag, id){
  	for(var i = 0; i < lable.length; i++){
		if(flag == lable[i].id){
			lable[i].fields.removeObjectById(id);
			
			break;
		}
     }  
    $(key).parent().parent().remove(); 
  }
	
  /* 显示添加标签弹出层 */
  function showLabel(){
    $.layer({
        type: 1,
        area: ['500', 'auto'],
        title: '添加产品标签',
        page: {dom : '#xf_ht_fkzh_ttc'}
     }); 
  }
          
  /* 显示添加字段弹出层 */
  function showFrame(flag){
    $("#flag").val(flag);

    $.layer({
        type: 1,
        area: ['500', 'auto'],
        title: '添加产品标签',
        page: {dom : '#xf_ht_off_ttc'}
     }); 
  }

  /* 关闭标签层 */
  function closeLabel(){
    $("#labelName").val('');
    layer.closeAll();
  }

  /* 关闭字段层 */
  function closeFrame(){
    $("#fieldName").val('');
    $("#fieldContent").val('');
    layer.closeAll();
  }
</script>
